package com.lcw.lostandfound.controller;

import com.lcw.lostandfound.pojo.Thank;
import com.lcw.lostandfound.service.ThankService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

@Controller
public class ThankController {

    @Autowired
    private ThankService thankService;

    @RequestMapping("/thank")
    public String thank(){
        return "thank";
    }
    @RequestMapping("/thankDetail")
    public String thankDetail(@RequestParam(name = "id")Integer id, Model model){
        model.addAttribute("thank",thankService.findById(id));
        return "ThankDetail";
    }
    @RequestMapping(value = "/releaseThank",method = RequestMethod.POST)
    public String releaseThank(Thank thank){
        thankService.insertThank(thank);
        Thank t = thankService.findByTitle(thank.getTitle());
        return "redirect:thankDetail?id="+t.getId();
    }
}
